from scapy.all import *
import time
import sys, getopt

class GEO(Packet):
    fields_desc=[ XBitField("version", None, 4),
                  XBitField("nh_basic", None, 4),
                  XBitField("reserved_basic", None, 8),
                  XBitField("lt", None, 8),
                  XBitField("rhl", None, 8),
                  XBitField("nh_common", None, 4),
                  XBitField("reserved_common_a", None, 4),
                  XBitField("ht", None, 4),
                  XBitField("hst", None, 4),
                  XBitField("tc", None, 8),
                  XBitField("flag", None, 8),
                  XBitField("pl", None, 16),
                  XBitField("mhl", None, 8),
                  XBitField("reserved_common_b", None, 8)
                  ]
class GBC(Packet):
    fields_desc=[ XBitField("sn", None, 16),
                  XBitField("reserved_gbc_a", None, 16),
                  XBitField("gnaddr", None, 64),
                  XBitField("tst", None, 32),
                  XBitField("lat", None, 32),
                  XBitField("longg", None, 32),
                  XBitField("pai", None, 1),
                  XBitField("s", None, 15),
                  XBitField("h", None, 16),
                  XBitField("geoAreaPosLat", None, 32),
                  XBitField("geoAreaPosLon", None, 32),
                  XBitField("disa", None, 16),
                  XBitField("disb", None, 16),
                  XBitField("angle", None, 16),
                  XBitField("reserved_gbc_b", None, 16)

                  ]

if __name__ == "__main__":

    L2=Ether(src=sys.argv[1],dst=sys.argv[2],type=0x8947)
    L3=GEO(ht=0x4)
    L4=GBC(geoAreaPosLat=int(sys.argv[3]),geoAreaPosLon=int(sys.argv[4]))
    pkt=L2/L3/L4
    pkt.show()
    hexdump(pkt)
    while 1:
        time.sleep(1)
        sendp(pkt, iface=sys.argv[5])

